<template>
	<el-drawer :title="titleMap[mode]" v-model="visible" :size="600" append-to-body destroy-on-close @closed="$emit('closed')">
		<el-container>
			<el-main class="nopadding">
				<el-scrollbar>
					<el-row class="drawer-table">
						<el-col :span="24">
							<el-form :model="form" :rules="rules" :disabled="mode==='show'" ref="dialogForm" label-width="80px">
								<el-input v-model="form.sellerId" type="hidden"></el-input>
								<el-form-item label="编码" prop="sellerNum">
									<el-input v-model="form.sellerNum" placeholder="请输入编码" clearable></el-input>
								</el-form-item>
								<el-form-item label="名称" prop="name">
									<el-input v-model="form.name" placeholder="请输入名称" clearable></el-input>
								</el-form-item>
								<el-form-item label="状态" prop="status">
									<el-select v-model="form.status" placeholder="状态" clearable>
										<el-option label="激活" :value="1"></el-option><el-option label="失效" :value="0"></el-option>
										<el-option label="待审核" :value="2"></el-option><el-option label="审核不通过" :value="3"></el-option>
									</el-select>
								</el-form-item>
								<el-form-item label="排序(降序)" prop="seq">
									<el-input v-model="form.seq" placeholder="请输入数字" clearable></el-input>
								</el-form-item>
								<el-form-item label="logo" prop="logo">
									<el-input v-model="form.logo" placeholder="请输入logo图片" clearable></el-input>
								</el-form-item>
                            </el-form>
						</el-col>
					</el-row>
				</el-scrollbar>
			</el-main>
			<el-footer>
				<el-button v-if="mode!=='show'" :loading="isSaveing" @click="submit()" type="primary" size="small">保 存</el-button>
				<el-button size="small" @click="visible=false">取 消</el-button>
			</el-footer>
		</el-container>
	</el-drawer>
</template>
<script>
	import sellerAPI from '@/api/seller/seller';
	export default {
		emits: ['success', 'closed'],
		data() {
			return {
				mode: "add",
				titleMap: {
					add: '新增',
					edit: '编辑',
					mode: ''
				},
				visible: false,
				isSaveing: false,
				//表单数据
				form: {
					sellerId: "",
					sysBranchOfficeId: "",
					sysUserId: "",
					sellerType: "",
					sellerNum: "",
					name: "",
					categoryPath: "",
					regionPath: "",
					status: "",
					saleStatus: "",
					seq: "",
					sketch: "",
					description: "",
					keyWords: "",
					logo: "",
					linkUrl: "",
					creditCount: "",
					level: "",
					tgLevel: "",
					buySeq: "",
				},
				//验证规则
				rules: {
					name: [
						{required: true, message: '请输入名称'}
					],
					sellerNum: [
						{required: true, message: '年龄需为数字', trigger: 'blur'}
					],
					seq: [
						{pattern: /^\d+(\.\d+)?$/, message: '排序号为数字', trigger: 'blur'}
					]
				}
			}
		},
		mounted() {

		},
		methods: {
			//显示
			open(mode='add'){
				this.mode = mode;
				this.visible = true;
				return this;
			},
			//表单提交方法
			submit(){
				this.$refs.dialogForm.validate(async (valid) => {
					if(valid){
						this.isSaveing = true;
						var res = await sellerAPI.seller.save.post(this.form);
						this.isSaveing = false;
						if(res.code === 2000){
							this.$emit('success', this.form, this.mode);
							this.visible = false;
							this.$message.success(res.message);
						}else{
							this.$alert(res.message, "提示", {type: 'error'})
						}
					}
				});
			},
			//表单注入数据
			setData(data){
				this.form.sellerId = data.sellerId;
				this.form.sysBranchOfficeId = data.sysBranchOfficeId;
				this.form.sysUserId = data.sysUserId;
				this.form.sellerType = data.sellerType;
				this.form.sellerNum = data.sellerNum;
				this.form.name = data.name;
				this.form.categoryPath = data.categoryPath;
				this.form.regionPath = data.regionPath;
				this.form.status = data.status;
				this.form.saleStatus = data.saleStatus;
				this.form.seq = data.seq;
				this.form.sketch = data.sketch;
				this.form.description = data.description;
				this.form.keyWords = data.keyWords;
				this.form.logo = data.logo;
				this.form.linkUrl = data.linkUrl;
				this.form.creditCount = data.creditCount;
				this.form.level = data.level;
				this.form.tgLevel = data.tgLevel;
				this.form.buySeq = data.buySeq;
			}
		}
	}
</script>
<style>
</style>
